(function() {
  var Utilites,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.CustomView = (function(_super) {

    __extends(CustomView, _super);

    function CustomView() {
      return CustomView.__super__.constructor.apply(this, arguments);
    }

    CustomView.prototype.initialize = function() {
      $(this.el).off();
      Loading.Start();
      _.bindAll(this);
      return this.model.view = this;
    };

    CustomView.prototype.Navigate = function(url, trigger, replace) {
      return Backbone.history.navigate(url.replace(window.UrlPrefix, ''), {
        trigger: trigger,
        replace: replace
      });
    };

    CustomView.prototype.GetTemplate = function(url, func) {
      return Utilites.GetTemplate(url, func, this.initializeValidate);
    };

    CustomView.prototype.initializeValidate = function() {
      var form;
      form = $(this.el).find("form");
      return form.find('input, textarea, select').each(function() {
        return $(this).Validator();
      });
    };

    CustomView.prototype.IsValid = function() {
      if ($(this.el).find("fieldset").find("div[data-error-message]").length) {
        return false;
      }
      return true;
    };

    return CustomView;

  })(Backbone.View);

  Utilites = (function() {

    function Utilites() {}

    Utilites.template = [];

    Utilites.GetTemplate = function(url, func, customFunc) {
      var cashedTemplate, resolvedUrl;
      resolvedUrl = url;
      if (Settings.Compress.IsEnabled) {
        resolvedUrl = url.replace("/myLibrary/", '/myLibrary/Content/') + '.html';
      }
      cashedTemplate = Utilites.template[url + Settings.Version];
      if (typeof cashedTemplate === 'undefined') {
        return $.ajax({
          url: resolvedUrl,
          cache: true,
          success: function(template) {
            var compiledTemplate;
            compiledTemplate = _.template(template);
            Utilites.template[url + Settings.Version] = compiledTemplate;
            func(compiledTemplate);
            customFunc();
            return Loading.Stop();
          },
          error: function() {
            Messages.WriteErrors([
              {
                Message: "Could not find template for url " + url
              }
            ]);
            Messages.WriteMessage("Trying get template with safe url");
            return $.ajax({
              url: url,
              cache: true,
              success: function(template) {
                var compiledTemplate;
                compiledTemplate = _.template(template);
                Utilites.template[url + Settings.Version] = compiledTemplate;
                func(compiledTemplate);
                customFunc();
                return Loading.Stop();
              }
            });
          }
        });
      } else {
        func(cashedTemplate);
        customFunc();
        return Loading.Stop();
      }
    };

    return Utilites;

  })();

}).call(this);
